import {
    createRouter,
    RouteRecordRaw,
    createWebHistory,
    createWebHashHistory,
    Router
} from 'vue-router'
import pages from './routePages'
let routesPage: any[] = []
Object.keys(pages as any).forEach(obj => {
    let routeObj = {
        path: '/' + obj,
        name: obj,
        meta: (pages as any)[obj].meta,
        component: (pages as any)[obj][obj]
    }
    routesPage.push(routeObj)
})
const routes: RouteRecordRaw[] = [
    ...routesPage,
    {
        path: '/',
        name: '/',
        redirect: '/dashboard'
    },
    {
        path: '/dashboard',
        name: 'dashboard',
        component: () => import('@/views/dashboard/dashboard.vue')
    }
]
const router: Router = createRouter({
    // history: createWebHashHistory(process.env.VUE_APP_BASE_URL),
    history: createWebHistory(process.env.VUE_APP_BASE_URL),
    routes
})

router.beforeEach((to, from, next) => {
    // 路由拦截  Do something
    next()
})

export default router